class ForumThreadsController < ApplicationController
  filter_access_to :all

  #
  def show
    @forum_thread = ForumThread.find(params[:id])
    @post = Post.new
    @forum_thread.views += 1
    @forum_thread.save!    
    store_location
  end

  #
  def new
    @forum_thread = ForumThread.new
    @post = Post.new
    #@forum = Forum.find(params[:forum_id])
  end

  #
  def create
    @forum_thread = ForumThread.new(params[:forum_thread])
    @post = Post.new(params[:posts])
    @forum = Forum.find(params[:forum_thread][:forum_id])
    @forum_thread.user_id = current_user.id

    if @forum.locked != true
      ForumThread.transaction do
        @forum_thread.save!
        @post.forum_thread = @forum_thread
        @post.user_id = current_user.id
        @post.save!
        flash[:notice] = "Thread created!"
        redirect_to_request_uri
        #redirect_to root_url
      end
    else
      flash[:error] = "That forum is locked."
      redirect_to root_url
    end
  end

  #
  def edit
    @forum_thread = ForumThread.find(params[:id])
  end

  #
  def update
    @forum_thread = ForumThread.find(params[:id])
     
    if @article.update_attributes(params[:article])
      flash[:notice] = "Successfully updated thread."
      redirect_to root_url
    else
      render :action => :edit
    end
  end

  #
  def destroy
    @forum_thread = ForumThread.find(params[:id])
    @forum_thread.destroy
    flash[:notice] = "Successfully removed thread."
    redirect_to root_url
  end

end
